/**
 * Includes several utility functions used in the
 * vector lib
 * @class Vector.util
 * @namespace Vector
 */
Vector.util = function(){
	return{
		/**
		 * Returns a random color rgb
		 * @returns rgb string
		 */
		randomColorString: function(){
			var redVal = Math.round(Math.random()*255);
		    var greenVal = Math.round(Math.random()*255);
   			var blueVal = Math.round(Math.random()*255);
         	return "rgb(" + redVal + "," + greenVal + "," + blueVal + ")";
		},
		deleteProps: function(obj, props){
			for(var i=0;i<props.length;i++){
				delete obj[props[i]];
			}
		},
		/**
		 * Set attributes on an html object
		 * @param {Object} obj
		 * @param {Object} attributes
		 */
		SA: function(obj, attributes){
			for(var i in attributes){
				obj.setAttribute(i, attributes[i]);
			}
		},
		/**
		 * Set attributes on an html object using the NS function
		 * this is used in firefox to activate the svg parser
		 * @param {Object} obj
		 * @param {Object} attributes
		 */
		SAN: function(obj, attributes){
			for(var i in attributes){
				obj.setAttributeNS(null,i, attributes[i]);
			}
		},
		setStyle: function(obj, attributes){
			for(var i in attributes){
				obj.style[i] = attributes[i];
			}
		}
	}
}();

/**
 * Base vector element object
 */
Vector.El = function(){
	this.Store = [];
	this.lookup = {};
	Vector.El.superclass.constructor.call(this);
}
Ext.extend(Vector.El, Ext.util.Observable,{
	createEl: function(ns,typ){
		return document.createElementNS(ns,typ);
	},
	deleteAll: function(){
		for(var i=0; i<this.Store.length; i++) {
			var el = Ext.get(this.Store[i].id);
			if(el){el.remove();}
			
		}
	},
	render: function(itemConfig){
		if(itemConfig){
    		if(!itemConfig.id){itemConfig.id=Ext.id();}
			this.Store.push(itemConfig);
			this.lookup[itemConfig.id] = this.Store.length - 1;
			this.draw(itemConfig);
		}else{
			this.draw({});
		}			
    },
    addItems: function(itemConfig){
    	for(var i=0; i<itemConfig.length; i++) {
    		if(!itemConfig[i].id){itemConfig[i].id=Ext.id();}
    		this.Store.push(itemConfig[i]);
    		this.lookup[itemConfig[i].id] = i;
    	}
    },
    renderAll: function(){
    	var o = null;
    	for(var i=0; i<this.Store.length; i++) {
    		o = this.Store[i];
    		this.draw(o);
    	}
    }	
});
/**
 * @class Vector.Line
 * @extends Ext.util.Observable
 * Simple Vector Line class
 * @cfg {String} Id optional to identify the line 
 * @cfg fromx fromy beginning point of line
 * @cfg tox toy end point of line
 * @cfg {Number} strokeweight width of line
 * @cfg {String} strokecolor color of line
 * @constructor
 * Create a new line
 * @param {String/HTMLElement/Element} renderTo The element to append the button to
 * @param {Object} config The config object
 */
Vector.Line = function(){
	this.config = {};
	Ext.applyIf(this.config,{strokeweight: '1px',strokecolor: 'red'});
	Vector.Line.superclass.constructor.call(this);
}
Ext.extend(Vector.Line, Vector.El, {});
/**
 * @class Ext.Polyline
 * @extends Ext.util.Observable
 * Simple Vector PolyLine class
 * @cfg {Number} strokeweight width of line
 * @cfg {Array} pts x and y pairs 
 * @cfg {String} strokecolor color of line
 * @constructor
 * Create a new line
 * @param {String/HTMLElement/Element} renderTo The element to append the button to
 * @param {Object} config The config object
 */
Vector.Polyline = function(){
	this.config = {};
	Vector.Polyline.superclass.constructor.call(this);
}
Ext.extend(Vector.Polyline, Vector.El, {
});	
/**
 * @class Ext.Box
 * @extends Ext.util.Observable
 * Simple Vector Rectangle class
 * @cfg {Number} strokeweight width of line
 * @cfg {String} strokecolor color of line
 * @constructor
 * @param {String/HTMLElement/Element} renderTo The element to append the button to
 * @param {Object} config The config object
 */
Vector.Box = function(){
	this.config = {};
	this.config.shadow = 'true';
   this.config.strokecolor = 'black';
   this.config.strokeweight = '4px';
   this.config.cls ='graph-box';
   this.config.left = 0;
   this.config.top = 0;
   this.config.text = '';
   this.config.fill =false;
   this.config.fillcolor='gray';
   this.config.height = '50px';
   this.config.width = '50px';
   this.id = Ext.id();
   	Vector.Box.superclass.constructor.call(this);
}
Ext.extend(Vector.Box, Vector.El, {});	

Vector.RoundBox = function(){
	this.config = {};
	Vector.RoundBox.superclass.constructor.call(this);
	}
Ext.extend(Vector.RoundBox, Vector.Box, {});	

Vector.Group = function(){
	Ext.applyIf(this,{left: 0,top: 0,width: 250,height: 250});
	Vector.Group.superclass.constructor.call(this);
}
Ext.extend(Vector.Group,Vector.El,{});

